package helper;

import net.sourceforge.pinyin4j.PinyinHelper;

public class PinYingHelper {
	/**
	 * 获取拼音码
	 * @param str
	 * @return
	 */
	public static String getPinYing(String str){
		if(str == null)return null;
		String restr = "";
		for(int i=0; i<str.length(); i++){
			if((str.charAt(i) + "").matches("[\\d\\w\\s]+")){
				restr = restr + str.charAt(i);
			}else{
				String[] py = PinyinHelper.toHanyuPinyinStringArray(str.charAt(i));
				if(py != null && py.length > 0 && py[0].length() > 0){
					restr = restr + py[0].substring(0, 1).toUpperCase();
				}
			}
		}
		return restr;
	}
	public static void main(String[] args) {
		System.out.println(getPinYing("您好tony!"));
	}
}
